package com.breakfast.fun.ui.user.invite;

import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.breakfast.fun.adapter.user.UserInviteAdapter;
import com.breakfast.fun.base.BaseActivity;
import com.breakfast.fun.data.entity.user.invite.InviteData;
import com.breakfast.fun.view.widget.TitleBarView;
import com.breakfast.fun.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.List;

import butterknife.Bind;

public class UserInviteActivity extends BaseActivity<UserInvitePresenter, UserInviteModel> implements UserInviteContract.View {


    @Bind(R.id.tbv_user_invite)
    TitleBarView tbvUserInvite;
    @Bind(R.id.lv_user_invite)
    ListView lvUserInvite;
    @Bind(R.id.iv_invite_empty)
    ImageView ivInviteEmpty;

    private UserInviteAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_user_invite;
    }

    @Override
    public void initView() {
        EventBus.getDefault().register(this);
        tbvUserInvite.setBack(this);
        tbvUserInvite.setTitleNoRight("邀请记录");


    }

    @Override
    public void showInvite(List<InviteData> inviteDataList) {
        if (inviteDataList.size() == 0) {
            ivInviteEmpty.setVisibility(View.VISIBLE);
            lvUserInvite.setVisibility(View.GONE);
        } else {
            adapter = new UserInviteAdapter(context, inviteDataList);
            lvUserInvite.setAdapter(adapter);
        }
    }

    @Subscribe
    public void onEventMainThread(InviteData data) {
        presenter.remind(data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
